package sbt;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.*;
import sbt.webdriver.WebDriverFactory;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

import sbt.model.User;

public class Login extends sbt.pages.TestBase {
  @BeforeMethod
  public void mayBeLogout(){
  }
  @Test
  public void testLoginOK() throws Exception {
    User user = new User().setLogin("admin").setPassword("admin");
	app.getUserHelper().loginAs(user);
	assertTrue(app.getUserHelper().isLoggedInAs(user));
  } 
 
  @Test
  public void testLoginFailed() throws Exception{
	  	User user = new User().setLogin("admin").setPassword("wrong");
	  	app.getUserHelper().loginAs(user);
	  	assertTrue(app.getUserHelper().isNotLoggedIn());
  }
  @AfterMethod
  public void testLogout() throws Exception{
	  if (app.getUserHelper().isLoggedIn())
		  app.getUserHelper().logout();

  }

}
